<template>
  <admin-layout>
    <h1>list</h1>
    <el-table
      :data="tableData"
      style="width: 100%"
      empty-text="暂无数据"
      v-loading="isLoading"
    >
      <!--          <template #empty>
        暂无数据empty
      </template>-->
      <el-table-column label="日期">
        <template #default="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.date }}</span>
        </template>
      </el-table-column>
      <el-table-column label="姓名">
        <template #default="scope">
          <el-popover effect="light" trigger="hover" placement="top">
            <template #default>
              <p>姓名: {{ scope.row.name }}</p>
              <p>住址: {{ scope.row.address }}</p>
            </template>
            <template #reference>
              <div class="name-wrapper">
                <el-tag size="medium">{{ scope.row.name }}</el-tag>
              </div>
            </template>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)"
          >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
          >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </admin-layout>
</template>

<script>
import { mapActions, mapState } from "vuex";
import logo from '@/assets/logo.png'

export default {
  name: "Home",
  computed: {
    ...mapState("contact", ["tableData"]),
  },
  data() {
    return {
      logo,
      isLoading: false,
    };
  },
  async created() {
    this.isLoading = true;
    try {
      await this.getList();
    } catch (e) {
      // this.isLoading = false
      this.$message.error("网络错误");
    } finally {
      this.isLoading = false;
    }
  },
  methods: {
    ...mapActions("contact", ["getList"]),
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
  },
};
</script>

<style lang="less" scoped>
.el-header {
  background-color: #ff9796;
  display: flex;
  align-items: center;

  ul {
    display: flex;
    align-items: center;
    font-size: 20px;
    margin: 0;
    list-style: none;

    li {
      padding: 0 10px;
    }
  }
}
.el-aside {
  background-color: #42b983;
}

.el-main {
  height: calc(100vh - 60px);
}
</style>
